2dbeefe3f0b35d28d97c8ff56282456474556ddf
3 * Core installer command line interface.
10 * Class for the core installer command line interface.
15 class CliInstaller
extends Installer
{
16 private $specifiedScriptPath = false;
18 private $optionMap = array(
19 'dbtype' => 'wgDBtype',
20 'dbserver' => 'wgDBserver',
21 'dbname' => 'wgDBname',
22 'dbuser' => 'wgDBuser',
23 'dbpass' => 'wgDBpassword',
24 'dbprefix' => 'wgDBprefix',
25 'dbtableoptions' => 'wgDBTableOptions',
26 'dbmysql5' => 'wgDBmysql5',
27 'dbport' => 'wgDBport',
28 'dbschema' => 'wgDBmwschema',
29 'dbpath' => 'wgSQLiteDataDir',
30 'server' => 'wgServer',
31 'scriptpath' => 'wgScriptPath',
39 * @param $option Array
41 function __construct( $siteName, $admin = null, array $option = array() ) {
44 parent
::__construct();
46 if ( isset( $option['scriptpath'] ) ) {
47 $this->specifiedScriptPath
= true;
50 foreach ( $this->optionMap
as $opt => $global ) {
51 if ( isset( $option[$opt] ) ) {
52 $GLOBALS[$global] = $option[$opt];
53 $this->setVar( $global, $option[$opt] );
57 if ( isset( $option['lang'] ) ) {
58 global $wgLang, $wgLanguageCode;
59 $this->setVar( '_UserLang', $option['lang'] );
60 $wgContLang = Language
::factory( $option['lang'] );
61 $wgLang = Language
::factory( $option['lang'] );
62 $wgLanguageCode = $option['lang'];
65 $this->setVar( 'wgSitename', $siteName );
67 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
68 if ( $metaNS == 'MediaWiki' ) {
71 $this->setVar( 'wgMetaNamespace', $metaNS );
74 $this->setVar( '_AdminName', $admin );
77 if ( !isset( $option['installdbuser'] ) ) {
78 $this->setVar( '_InstallUser',
79 $this->getVar( 'wgDBuser' ) );
80 $this->setVar( '_InstallPassword',
81 $this->getVar( 'wgDBpassword' ) );
83 $this->setVar( '_InstallUser',
84 $option['installdbuser'] );
85 $this->setVar( '_InstallPassword',
86 isset( $option['installdbpass'] ) ?
$option['installdbpass'] : "" );
88 // Assume that if we're given the installer user, we'll create the account.
89 $this->setVar( '_CreateDBAccount', true );
92 if ( isset( $option['pass'] ) ) {
93 $this->setVar( '_AdminPassword', $option['pass'] );
100 public function execute() {
101 $vars = Installer
::getExistingLocalSettings();
103 $this->showStatusMessage(
104 Status
::newFatal( "config-localsettings-cli-upgrade" )
108 $this->performInstallation(
109 array( $this, 'startStage' ),
110 array( $this, 'endStage' )
115 * Write LocalSettings.php to a given path
117 * @param $path String Full path to write LocalSettings.php to
119 public function writeConfigurationFile( $path ) {
120 $ls = new LocalSettingsGenerator( $this );
121 $ls->writeFile( "$path/LocalSettings.php" );
124 public function startStage( $step ) {
125 $this->showMessage( "config-install-$step" );
128 public function endStage( $step, $status ) {
129 $this->showStatusMessage( $status );
130 $this->showMessage( 'config-install-step-done' );
133 public function showMessage( $msg /*, ... */ ) {
134 echo $this->getMessageText( func_get_args() ) . "\n";
138 public function showError( $msg /*, ... */ ) {
139 echo "***{$this->getMessageText( func_get_args() )}***\n";
144 * @param $params array
148 protected function getMessageText( $params ) {
149 $msg = array_shift( $params );
151 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
153 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
154 return html_entity_decode( strip_tags( $text ), ENT_QUOTES
);
160 public function showHelpBox( $msg /*, ... */ ) {
163 public function showStatusMessage( Status
$status ) {
164 $warnings = array_merge( $status->getWarningsArray(),
165 $status->getErrorsArray() );
167 if ( count( $warnings ) !== 0 ) {
168 foreach ( $warnings as $w ) {
169 call_user_func_array( array( $this, 'showMessage' ), $w );
173 if ( !$status->isOk() ) {
179 public function envCheckPath( ) {
180 if ( !$this->specifiedScriptPath
) {
181 $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") );
183 return parent
::envCheckPath();
186 protected function envCheckServer( $srv = null ) {
187 if ( $this->getVar( 'wgServer' ) ) {
188 $srv = $this->getVar( 'wgServer' );
190 return parent
::envCheckServer( $srv );
193 public function dirIsExecutable( $dir, $url ) {
194 $this->showMessage( 'config-no-cli-uploads-check', $dir );